package org.zero.mapstruct.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import org.zero.model.bo.UserBO;
import org.zero.model.po.UserPO;
import org.zero.model.vo.UserVO;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/9/4 16:00
 */
@Mapper(componentModel = "spring")
public interface UserMapper {
    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    @Mappings({
            @Mapping(target = "username", source = "name"),
            @Mapping(target = "gender",
                    expression = "java(org.zero.util.EnumUtils.getEnum(org.zero.model.constant.GenderEnum.class,source.getGender()))"),
            @Mapping(target = "deleted", expression = "java(org.zero.mapstruct.converter.NumBoolConverter.byte2Bool(source.getDeleted()))"),
            @Mapping(target = "account", ignore = true)
    })
    UserBO po2Bo(UserPO source);

//    @InheritInverseConfiguration
//    UserPO bo2Po(UserBO source);

    @Mappings({
            @Mapping(target = "username", source = "name"),
            @Mapping(target = "gender",
                    expression = "java(org.zero.util.EnumUtils.getOtherKey(org.zero.model.constant.GenderEnum.class,source.getGender(),\"name\",java.lang.String.class))"),
            @Mapping(target = "birthday",
                    dateFormat = "yyyy-MM-dd"),
            @Mapping(target = "account", ignore = true)
    })
    UserVO po2Vo(UserPO source);
}
